<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
 Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="Connection.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>Connection.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'Connection.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="draw2d/Connection.html">draw2d.Connection</a></b></td>
    <td>A Connection is the line between two <a href="../draw2d/Port.html#">draw2d.Port</a>s.</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/* This notice must be untouched at all times.

FreeGroup Draw2D 0.9.26
The latest version is available at
http://www.freegroup.de

Copyright (c) 2006 Andreas Herz. All rights reserved.
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )

LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,
or see http://www.gnu.org/copyleft/lesser.html
*/</span>

<span class="comment">/**
 * <span class="attrib">@class</span> A Connection is the line between two {<span class="attrib">@link</span> draw2d.Port}s.
 *
 * <span class="attrib">@version</span> 0.9.26
 * <span class="attrib">@author</span> Andreas Herz
 * <span class="attrib">@constructor</span>
 */</span>
draw2d.Connection=<span class="reserved">function</span>()
{
  draw2d.Line.call(<span class="reserved">this</span>);

  <span class="comment">/** <span class="attrib">@private</span> **/</span>
  <span class="reserved">this</span>.sourcePort = null;
  <span class="comment">/** <span class="attrib">@private</span> **/</span>
  <span class="reserved">this</span>.targetPort = null;

  <span class="reserved">this</span>.canDrag = true;

  <span class="comment">/** <span class="attrib">@private</span> **/</span>
  <span class="reserved">this</span>.sourceDecorator = null; <span class="comment">/*:draw2d.ConnectionDecorator*/</span>

  <span class="comment">/** <span class="attrib">@private</span> **/</span>
  <span class="reserved">this</span>.targetDecorator = null; <span class="comment">/*:draw2d.ConnectionDecorator*/</span>

  <span class="comment">/** <span class="attrib">@private</span> **/</span>
  <span class="reserved">this</span>.sourceAnchor = new draw2d.ConnectionAnchor();

  <span class="comment">/** <span class="attrib">@private</span> **/</span>
  <span class="reserved">this</span>.targetAnchor = new draw2d.ConnectionAnchor();


  <span class="comment">/** <span class="attrib">@private</span> **/</span>
  <span class="reserved">this</span>.router = draw2d.Connection.defaultRouter;

  <span class="comment">/** <span class="attrib">@private</span> **/</span>
  <span class="reserved">this</span>.lineSegments = new draw2d.ArrayList();

  <span class="reserved">this</span>.children = new draw2d.ArrayList();

  <span class="reserved">this</span>.setColor(new  draw2d.Color(0,0,115));
  <span class="reserved">this</span>.setLineWidth(1);
};

draw2d.Connection.<span class="reserved">prototype</span> = new draw2d.Line();
draw2d.Connection.<span class="reserved">prototype</span>.type = <span class="literal">"draw2d.Connection"</span>;

draw2d.Connection.defaultRouter = new draw2d.ManhattanConnectionRouter();

draw2d.Connection.setDefaultRouter=<span class="reserved">function</span>(<span class="comment">/*:draw2d.ConnectionRouter*/</span> router)
{
   draw2d.Connection.defaultRouter = router;
};

<span class="comment">/**
 * <span class="attrib">@private</span>
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.disconnect=<span class="reserved">function</span>()
{
  <span class="reserved">if</span>(<span class="reserved">this</span>.sourcePort!==null)
  {
    <span class="reserved">this</span>.sourcePort.detachMoveListener(<span class="reserved">this</span>);
    <span class="reserved">this</span>.fireSourcePortRouteEvent();
  }

  <span class="reserved">if</span>(<span class="reserved">this</span>.targetPort!==null)
  {
    <span class="reserved">this</span>.targetPort.detachMoveListener(<span class="reserved">this</span>);
    <span class="reserved">this</span>.fireTargetPortRouteEvent();
  }
};

<span class="comment">/**
 * <span class="attrib">@private</span>
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.reconnect=<span class="reserved">function</span>()
{
  <span class="reserved">if</span>(<span class="reserved">this</span>.sourcePort!==null)
  {
    <span class="reserved">this</span>.sourcePort.attachMoveListener(<span class="reserved">this</span>);
    <span class="reserved">this</span>.fireSourcePortRouteEvent();
  }
  <span class="reserved">if</span>(<span class="reserved">this</span>.targetPort!==null)
  {
    <span class="reserved">this</span>.targetPort.attachMoveListener(<span class="reserved">this</span>);
    <span class="reserved">this</span>.fireTargetPortRouteEvent();
  }
};


<span class="comment">/**
 * You can't drag&amp;drop the resize handles of a connector.
 * <span class="attrib">@type</span> boolean
 * <span class="attrib">@deprecated</span> use getCanDrag instead
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.isResizeable=<span class="reserved">function</span>()
{
  <span class="reserved">return</span> <span class="reserved">this</span>.getCanDrag();
};

<span class="comment">/**
 * Switch on/off the drag drop behaviour of this object
 *
 * <span class="attrib">@param</span> {boolean} flag The new drag drop indicator
 * <span class="attrib">@since</span> 0.9.18
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.setCanDrag=<span class="reserved">function</span>(<span class="comment">/*:boolean*/</span>flag)
{
  <span class="reserved">this</span>.canDrag= flag;
};


<span class="comment">/**
 * Return [true] if the connection can be moved (reconnect).
 *
 * <span class="attrib">@type</span> boolean
 * <span class="attrib">@since</span> 0.9.18
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.getCanDrag=<span class="reserved">function</span>()
{
  <span class="reserved">return</span> <span class="reserved">this</span>.canDrag;
};

<span class="comment">/**
 * Add a child figure to the Connection. The hands over figure doesn't support drag&amp;drop 
 * operations. It's only a decorator for the connection.&lt;br&gt;
 * Main for labels or other fancy decorations :-)
 *
 * <span class="attrib">@param</span> {draw2d.Figure} figure the figure to add as decoration to the connection.
 * <span class="attrib">@param</span> {draw2d.ConnectionLocator} locator the locator for the child. 
**/</span>
draw2d.Connection.<span class="reserved">prototype</span>.addFigure=<span class="reserved">function</span>(<span class="comment">/*:draw2d.Figure*/</span> figure, <span class="comment">/*:draw2d.ConnectionLocator*/</span> locator)
{
  var entry = {}
  entry.figure  = figure;
  entry.locator = locator;

  <span class="reserved">this</span>.children.add(entry);
  <span class="reserved">if</span>(<span class="reserved">this</span>.graphics !==null)
    <span class="reserved">this</span>.paint();

  var oThis = <span class="reserved">this</span>;
  var mouseDown = <span class="reserved">function</span>()
  {
    var oEvent = arguments[0] || window.event;
    oEvent.returnValue = false;
    oThis.getWorkflow().setCurrentSelection(oThis);
    oThis.getWorkflow().showLineResizeHandles(oThis);
  }

  <span class="reserved">if</span> (figure.getHTMLElement().addEventListener)
    figure.getHTMLElement().addEventListener(<span class="literal">"mousedown"</span>, mouseDown, false);
  <span class="reserved">else</span> <span class="reserved">if</span> (figure.getHTMLElement().attachEvent)
     figure.getHTMLElement().attachEvent(<span class="literal">"onmousedown"</span>, mouseDown);
};

<span class="comment">/**
 * Set the ConnectionDecorator for this object.
 *
 * <span class="attrib">@param</span> {draw2d.ConnectionDecorator} the new source decorator for the connection
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.setSourceDecorator=<span class="reserved">function</span>(<span class="comment">/*:draw2d.ConnectionDecorator*/</span> decorator)
{
  <span class="reserved">this</span>.sourceDecorator = decorator;
  <span class="reserved">if</span>(<span class="reserved">this</span>.graphics !==null)
    <span class="reserved">this</span>.paint();
};

<span class="comment">/**
 * Get the current source ConnectionDecorator for this object.
 *
 * <span class="attrib">@type</span> draw2d.ConnectionDecorator
 * <span class="attrib">@since</span> 0.9.18
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.getSourceDecorator=<span class="reserved">function</span>()
{
  <span class="reserved">return</span> <span class="reserved">this</span>.sourceDecorator;
};

<span class="comment">/**
 * Set the ConnectionDecorator for this object.
 *
 * <span class="attrib">@param</span> {draw2d.ConnectionDecorator} the new target decorator for the connection
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.setTargetDecorator=<span class="reserved">function</span>(<span class="comment">/*:draw2d.ConnectionDecorator*/</span> decorator)
{
  <span class="reserved">this</span>.targetDecorator = decorator;
  <span class="reserved">if</span>(<span class="reserved">this</span>.graphics !==null)
    <span class="reserved">this</span>.paint();
};

<span class="comment">/**
 * Get the current target ConnectionDecorator for this object.
 *
 * <span class="attrib">@type</span> draw2d.ConnectionDecorator
 * <span class="attrib">@since</span> 0.9.18
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.getTargetDecorator=<span class="reserved">function</span>()
{
  <span class="reserved">return</span> <span class="reserved">this</span>.targetDecorator;
};

<span class="comment">/**
 * Set the ConnectionAnchor for this object. An anchor is responsible for the endpoint calculation
 * of an connection.
 *
 * <span class="attrib">@param</span> {draw2d.ConnectionAnchor} the new source anchor for the connection
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.setSourceAnchor=<span class="reserved">function</span>(<span class="comment">/*:draw2d.ConnectionAnchor*/</span> anchor)
{
  <span class="reserved">this</span>.sourceAnchor = anchor;
  <span class="reserved">this</span>.sourceAnchor.setOwner(<span class="reserved">this</span>.sourcePort);
  <span class="reserved">if</span>(<span class="reserved">this</span>.graphics !==null)
    <span class="reserved">this</span>.paint();
};

<span class="comment">/**
 * Set the ConnectionAnchor for this object.
 *
 * <span class="attrib">@param</span> {draw2d.ConnectionAnchor} the new target anchor for the connection
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.setTargetAnchor=<span class="reserved">function</span>(<span class="comment">/*:draw2d.ConnectionAnchor*/</span> anchor)
{
  <span class="reserved">this</span>.targetAnchor = anchor;
  <span class="reserved">this</span>.targetAnchor.setOwner(<span class="reserved">this</span>.targetPort);
  <span class="reserved">if</span>(<span class="reserved">this</span>.graphics !==null)
    <span class="reserved">this</span>.paint();
};


<span class="comment">/**
 * Set the ConnectionRouter for this object.
 *
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.setRouter=<span class="reserved">function</span>(<span class="comment">/*:draw2d.ConnectionRouter*/</span> router)
{
  <span class="reserved">if</span>(router !==null)
   <span class="reserved">this</span>.router = router;
  <span class="reserved">else</span>
   <span class="reserved">this</span>.router = new draw2d.NullConnectionRouter();

  <span class="comment">// repaint the connection with the new router</span>
  <span class="reserved">if</span>(<span class="reserved">this</span>.graphics !==null)
     <span class="reserved">this</span>.paint();
};

<span class="comment">/**
 * Return the current active router of this connection.
 *
 * <span class="attrib">@type</span> draw2d.ConnectionRouter
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.getRouter=<span class="reserved">function</span>()
{
  <span class="reserved">return</span> <span class="reserved">this</span>.router;
};

draw2d.Connection.<span class="reserved">prototype</span>.setWorkflow= <span class="reserved">function</span>(<span class="comment">/*:draw2d.Workflow*/</span> workflow)
{
  draw2d.Line.<span class="reserved">prototype</span>.setWorkflow.call(<span class="reserved">this</span>,workflow);
  <span class="reserved">for</span>(var i=0; i&lt;<span class="reserved">this</span>.children.getSize();i++)
  {
     <span class="reserved">this</span>.children.get(i).isAppended=false;
  }
};

<span class="comment">/**
 * <span class="attrib">@private</span>
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.paint=<span class="reserved">function</span>()
{
   <span class="reserved">if</span>(<span class="reserved">this</span>.html===null)
     <span class="reserved">return</span>; <span class="comment">// silently</span>

   try
   {
    <span class="comment">// Hack for the IE:</span>
    <span class="comment">// All HTML fragments of the children are corrupt If I clear the graphics context</span>
    <span class="comment">// This doesn't happens with the firefox.</span>
    <span class="comment">//</span>
    <span class="comment">// remove first the children before we set the innerHTML of the context to "";</span>
    <span class="comment">//</span>
    <span class="reserved">for</span>(var i=0; i&lt;<span class="reserved">this</span>.children.getSize();i++)
    {
        var entry = <span class="reserved">this</span>.children.get(i);
        <span class="reserved">if</span>(entry.isAppended==true)
          <span class="reserved">this</span>.html.removeChild(entry.figure.getHTMLElement());
        entry.isAppended=false;
    }

    <span class="reserved">if</span>(<span class="reserved">this</span>.graphics===null)
      <span class="reserved">this</span>.graphics = new jsGraphics(<span class="reserved">this</span>.html);
    <span class="reserved">else</span>
      <span class="reserved">this</span>.graphics.clear();

    <span class="reserved">this</span>.graphics.setStroke(<span class="reserved">this</span>.stroke);
    <span class="reserved">this</span>.graphics.setColor(<span class="reserved">this</span>.lineColor.getHTMLStyle());

    <span class="reserved">this</span>.startStroke();

    <span class="comment">// Use the internal router if any has been set....</span>
    <span class="comment">//</span>
    <span class="reserved">this</span>.router.route(<span class="reserved">this</span>);

    <span class="comment">// paint the decorator if any exists</span>
    <span class="comment">//</span>
    <span class="reserved">if</span>(<span class="reserved">this</span>.getSource().getParent().isMoving==false &amp;&amp; <span class="reserved">this</span>.getTarget().getParent().isMoving==false )
    {
      <span class="reserved">if</span>(<span class="reserved">this</span>.targetDecorator!==null)
        <span class="reserved">this</span>.targetDecorator.paint(new draw2d.Graphics(<span class="reserved">this</span>.graphics,<span class="reserved">this</span>.getEndAngle(),<span class="reserved">this</span>.getEndPoint()));

      <span class="reserved">if</span>(<span class="reserved">this</span>.sourceDecorator!==null)
        <span class="reserved">this</span>.sourceDecorator.paint(new draw2d.Graphics(<span class="reserved">this</span>.graphics,<span class="reserved">this</span>.getStartAngle(),<span class="reserved">this</span>.getStartPoint()));
    }
    <span class="reserved">this</span>.finishStroke();

    <span class="reserved">for</span>(var i=0; i&lt;<span class="reserved">this</span>.children.getSize();i++)
    {
        var entry = <span class="reserved">this</span>.children.get(i);
        <span class="reserved">this</span>.html.appendChild(entry.figure.getHTMLElement());
        entry.isAppended=true;
        entry.locator.relocate(entry.figure);
    }
  }
  catch(e)
  {
      pushErrorStack(e,<span class="literal">"draw2d.Connection.prototype.paint=function()"</span>);
  }
};

<span class="comment">/**
 * Return the recalculated position of the start point if we have set an anchor.
 * 
 * <span class="attrib">@type</span> draw2d.Point
 **/</span>
 draw2d.Connection.<span class="reserved">prototype</span>.getStartPoint=<span class="reserved">function</span>()
 {
  <span class="reserved">if</span>(<span class="reserved">this</span>.isMoving==false)
     <span class="reserved">return</span> <span class="reserved">this</span>.sourceAnchor.getLocation(<span class="reserved">this</span>.targetAnchor.getReferencePoint());
  <span class="reserved">else</span>
     <span class="reserved">return</span> draw2d.Line.<span class="reserved">prototype</span>.getStartPoint.call(<span class="reserved">this</span>);
 }


<span class="comment">/**
 * Return the recalculated position of the start point if we have set an anchor.
 *
 * <span class="attrib">@type</span> draw2d.Point
 **/</span>
 draw2d.Connection.<span class="reserved">prototype</span>.getEndPoint=<span class="reserved">function</span>()
 {
  <span class="reserved">if</span>(<span class="reserved">this</span>.isMoving==false)
     <span class="reserved">return</span> <span class="reserved">this</span>.targetAnchor.getLocation(<span class="reserved">this</span>.sourceAnchor.getReferencePoint());
  <span class="reserved">else</span>
     <span class="reserved">return</span> draw2d.Line.<span class="reserved">prototype</span>.getEndPoint.call(<span class="reserved">this</span>);
 }


<span class="comment">/**
 * <span class="attrib">@private</span>
 *
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.startStroke=<span class="reserved">function</span>()
{
 <span class="reserved">this</span>.oldPoint=null;
 <span class="reserved">this</span>.lineSegments = new draw2d.ArrayList();
};

<span class="comment">/**
 * <span class="attrib">@private</span>
 *
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.finishStroke=<span class="reserved">function</span>()
{
  <span class="reserved">this</span>.graphics.paint();
  <span class="reserved">this</span>.oldPoint=null;
};

<span class="comment">/**
 * Returns the fulcrums of the connection
 *
 * <span class="attrib">@return</span> an draw2d.ArrayList of type draw2d.Point
 * <span class="attrib">@type</span> draw2d.ArrayList 
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.getPoints=<span class="reserved">function</span>()
{
  var result = new draw2d.ArrayList();
  var line=null;
  <span class="reserved">for</span>(var i = 0; i&lt; <span class="reserved">this</span>.lineSegments.getSize();i++)
  {
     line = <span class="reserved">this</span>.lineSegments.get(i);
     result.add(line.start);
  }
  <span class="comment">// add the last point</span>
  <span class="reserved">if</span>(line!==null)
    result.add(line.end);
  <span class="reserved">return</span> result;
};

<span class="comment">/*
 * <span class="attrib">@private</span>
 *
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.addPoint=<span class="reserved">function</span>(<span class="comment">/*:draw2d.Point*/</span> p)
{
  p = new draw2d.Point(parseInt(p.x), parseInt(p.y));
  <span class="reserved">if</span>(<span class="reserved">this</span>.oldPoint!==null)
  {
    <span class="reserved">this</span>.graphics.drawLine(<span class="reserved">this</span>.oldPoint.x,<span class="reserved">this</span>.oldPoint.y, p.x, p.y);
<span class="comment">// For ConnectionRouter debugging only. All fulcrum point will be marked.</span>
<span class="comment">//</span>
<span class="comment">//    this.graphics.fillEllipse(p.x-3, p.y-3,6,6); </span>
<span class="comment">//    this.graphics.drawString(""+this.lineSegments.length,p.x, p.y);</span>

    <span class="comment">// store the painted line segment for the "mouse selection test"</span>
    <span class="comment">// (required for user interaction)</span>
    var line = {}
    line.start = <span class="reserved">this</span>.oldPoint;
    line.end   = p;
    <span class="reserved">this</span>.lineSegments.add(line);
  }


  <span class="reserved">this</span>.oldPoint = {}
  <span class="reserved">this</span>.oldPoint.x = p.x;
  <span class="reserved">this</span>.oldPoint.y = p.y;
};



<span class="comment">/**
 * Called by the inherit class if the source port model of the connections has been changed.&lt;br&gt;
 * Only used if you are working with the MVC pattern.
 *
 * <span class="attrib">@since</span> 0.9.18
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.refreshSourcePort=<span class="reserved">function</span>()
{
   var model    = <span class="reserved">this</span>.getModel().getSourceModel();
   var portName = <span class="reserved">this</span>.getModel().getSourcePortName();
   <span class="comment">// try to find the corresponding port in the workflow document to this model</span>
   <span class="comment">//</span>
   var figures = <span class="reserved">this</span>.getWorkflow().getDocument().getFigures();
   var count = figures.getSize();
   <span class="reserved">for</span>(var i=0;i&lt;count;i++)
   {
      var figure = figures.get(i);
      <span class="reserved">if</span>(figure.getModel()==model)
      {
        var port = figure.getOutputPort(portName);
        <span class="reserved">this</span>.setSource(port);
      }
   }
   <span class="reserved">this</span>.setRouter(<span class="reserved">this</span>.getRouter());
};

<span class="comment">/**
 * Called by the inherit class if the target port model of the connections has been changed.&lt;br&gt;
 * Only used if you are working with the MVC pattern.
 *
 * <span class="attrib">@since</span> 0.9.18
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.refreshTargetPort=<span class="reserved">function</span>()
{
   var model    = <span class="reserved">this</span>.getModel().getTargetModel();
   var portName = <span class="reserved">this</span>.getModel().getTargetPortName();
   <span class="comment">// try to find the corresponding port in the workflow document to this model</span>
   <span class="comment">//</span>
   var figures = <span class="reserved">this</span>.getWorkflow().getDocument().getFigures();
   var count = figures.getSize();
   <span class="reserved">for</span>(var i=0;i&lt;count;i++)
   {
      var figure = figures.get(i);
      <span class="reserved">if</span>(figure.getModel()==model)
      {
        var port = figure.getInputPort(portName);
        <span class="reserved">this</span>.setTarget(port);
      }
   }
   <span class="reserved">this</span>.setRouter(<span class="reserved">this</span>.getRouter());
};
<span class="comment">/**
 * Set the new source port of this connection. This enforce a repaint of the connection.
 *
 * <span class="attrib">@param</span> {draw2d.Port} port The new source port of this connection.
 * 
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.setSource=<span class="reserved">function</span>(<span class="comment">/*:draw2d.Port*/</span> port)
{
  <span class="reserved">if</span>(<span class="reserved">this</span>.sourcePort!==null)
    <span class="reserved">this</span>.sourcePort.detachMoveListener(<span class="reserved">this</span>);

  <span class="reserved">this</span>.sourcePort = port;
  <span class="reserved">if</span>(<span class="reserved">this</span>.sourcePort===null)
    <span class="reserved">return</span>;
  <span class="reserved">this</span>.sourceAnchor.setOwner(<span class="reserved">this</span>.sourcePort);
  <span class="reserved">this</span>.fireSourcePortRouteEvent();
  <span class="reserved">this</span>.sourcePort.attachMoveListener(<span class="reserved">this</span>);
  <span class="reserved">this</span>.setStartPoint(port.getAbsoluteX(), port.getAbsoluteY());
};

<span class="comment">/**
 * Returns the source port of this connection.
 *
 * <span class="attrib">@type</span> draw2d.Port
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.getSource=<span class="reserved">function</span>()
{
  <span class="reserved">return</span> <span class="reserved">this</span>.sourcePort;
};

<span class="comment">/**
 * Set the target port of this connection. This enforce a repaint of the connection.
 * 
 * <span class="attrib">@param</span> {draw2d.Port} port The new target port of this connection
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.setTarget=<span class="reserved">function</span>(<span class="comment">/*:draw2d.Port*/</span> port)
{
  <span class="reserved">if</span>(<span class="reserved">this</span>.targetPort!==null)
    <span class="reserved">this</span>.targetPort.detachMoveListener(<span class="reserved">this</span>);

  <span class="reserved">this</span>.targetPort = port;
  <span class="reserved">if</span>(<span class="reserved">this</span>.targetPort===null)
    <span class="reserved">return</span>;
  <span class="reserved">this</span>.targetAnchor.setOwner(<span class="reserved">this</span>.targetPort);
  <span class="reserved">this</span>.fireTargetPortRouteEvent();
  <span class="reserved">this</span>.targetPort.attachMoveListener(<span class="reserved">this</span>);
  <span class="reserved">this</span>.setEndPoint(port.getAbsoluteX(), port.getAbsoluteY());
};

<span class="comment">/**
 * Returns the target port of this connection.
 *
 * <span class="attrib">@type</span> draw2d.Port
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.getTarget=<span class="reserved">function</span>()
{
  <span class="reserved">return</span> <span class="reserved">this</span>.targetPort;
};

<span class="comment">/**
 * <span class="attrib">@see</span> draw2d.Figure#onOtherFigureMoved
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.onOtherFigureMoved=<span class="reserved">function</span>(<span class="comment">/*:draw2d.Figure*/</span> figure)
{
  <span class="reserved">if</span>(figure==<span class="reserved">this</span>.sourcePort)
    <span class="reserved">this</span>.setStartPoint(<span class="reserved">this</span>.sourcePort.getAbsoluteX(), <span class="reserved">this</span>.sourcePort.getAbsoluteY());
  <span class="reserved">else</span>
    <span class="reserved">this</span>.setEndPoint(<span class="reserved">this</span>.targetPort.getAbsoluteX(), <span class="reserved">this</span>.targetPort.getAbsoluteY());
};

<span class="comment">/**
 * Checks if the hands over coordinate hits the line.
 *
 * <span class="attrib">@param</span> {int} px the x coordinate of the test point
 * <span class="attrib">@param</span> {int} py the y coordinate of the test point
 * <span class="attrib">@type</span> boolean
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.containsPoint=<span class="reserved">function</span>(<span class="comment">/*:int*/</span> px, <span class="comment">/*:int*/</span> py)
{
  <span class="reserved">for</span>(var i = 0; i&lt; <span class="reserved">this</span>.lineSegments.getSize();i++)
  {
     var line = <span class="reserved">this</span>.lineSegments.get(i);
     <span class="reserved">if</span>(draw2d.Line.hit(<span class="reserved">this</span>.corona, line.start.x,line.start.y,line.end.x, line.end.y, px,py))
       <span class="reserved">return</span> true;
  }
  <span class="reserved">return</span> false;
};

<span class="comment">/**
 * Returns the angle of the connection at the output port (source)
 *
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.getStartAngle=<span class="reserved">function</span>()
{
  var p1 = <span class="reserved">this</span>.lineSegments.get(0).start;
  var p2 = <span class="reserved">this</span>.lineSegments.get(0).end;
  <span class="reserved">if</span>(<span class="reserved">this</span>.router instanceof draw2d.BezierConnectionRouter)
  {
   p2 = <span class="reserved">this</span>.lineSegments.get(5).end;
  }
  var length = Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
  var angle = -(180/Math.PI) *Math.asin((p1.y-p2.y)/length);

  <span class="reserved">if</span>(angle&lt;0)
  {
     <span class="reserved">if</span>(p2.x&lt;p1.x)
       angle = Math.abs(angle) + 180;
     <span class="reserved">else</span>
       angle = 360- Math.abs(angle);
  }
  <span class="reserved">else</span>
  {
     <span class="reserved">if</span>(p2.x&lt;p1.x)
       angle = 180-angle;
  }
  <span class="reserved">return</span> angle;
};

draw2d.Connection.<span class="reserved">prototype</span>.getEndAngle=<span class="reserved">function</span>()
{
  <span class="reserved">if</span> (<span class="reserved">this</span>.lineSegments.getSize() === 0) 
    <span class="reserved">return</span> 90;

  var p1 = <span class="reserved">this</span>.lineSegments.get(<span class="reserved">this</span>.lineSegments.getSize()-1).end;
  var p2 = <span class="reserved">this</span>.lineSegments.get(<span class="reserved">this</span>.lineSegments.getSize()-1).start;
  <span class="reserved">if</span>(<span class="reserved">this</span>.router instanceof draw2d.BezierConnectionRouter)
  {
   p2 = <span class="reserved">this</span>.lineSegments.get(<span class="reserved">this</span>.lineSegments.getSize()-5).end;
  }
  var length = Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
  var angle = -(180/Math.PI) *Math.asin((p1.y-p2.y)/length);

  <span class="reserved">if</span>(angle&lt;0)
  {
     <span class="reserved">if</span>(p2.x&lt;p1.x)
       angle = Math.abs(angle) + 180;
     <span class="reserved">else</span>
       angle = 360- Math.abs(angle);
  }
  <span class="reserved">else</span>
  {
     <span class="reserved">if</span>(p2.x&lt;p1.x)
       angle = 180-angle;
  }
  <span class="reserved">return</span> angle;
};


<span class="comment">/**
 * <span class="attrib">@private</span>
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.fireSourcePortRouteEvent=<span class="reserved">function</span>()
{
    <span class="comment">// enforce a repaint of all connections which are related to this port</span>
    <span class="comment">// this is required for a "FanConnectionRouter" or "ShortesPathConnectionRouter"</span>
    <span class="comment">//</span>
   var connections = <span class="reserved">this</span>.sourcePort.getConnections();
   <span class="reserved">for</span>(var i=0; i&lt;connections.getSize();i++)
   {
      connections.get(i).paint();
   }
};

<span class="comment">/**
 * <span class="attrib">@private</span>
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.fireTargetPortRouteEvent=<span class="reserved">function</span>()
{
    <span class="comment">// enforce a repaint of all connections which are related to this port</span>
    <span class="comment">// this is required for a "FanConnectionRouter" or "ShortesPathConnectionRouter"</span>
    <span class="comment">//</span>
   var connections = <span class="reserved">this</span>.targetPort.getConnections();
   <span class="reserved">for</span>(var i=0; i&lt;connections.getSize();i++)
   {
      connections.get(i).paint();
   }
};


<span class="comment">/**
 * Returns the Command to perform the specified Request or null.
  *
 * <span class="attrib">@param</span> {draw2d.EditPolicy} request describes the Command being requested
 * <span class="attrib">@return</span> null or a Command
 * <span class="attrib">@type</span> draw2d.Command
 * <span class="attrib">@since</span> 0.9.15
 **/</span>
draw2d.Connection.<span class="reserved">prototype</span>.createCommand=<span class="reserved">function</span>(<span class="comment">/*:draw2d.EditPolicy*/</span> request)
{
  <span class="reserved">if</span>(request.getPolicy() == draw2d.EditPolicy.MOVE)
  {
    <span class="comment">// DragDrop of a connection doesn't create a undo command at this point. This will be done in</span>
    <span class="comment">// the onDrop method</span>
    <span class="reserved">return</span> new draw2d.CommandReconnect(<span class="reserved">this</span>);
  }
  <span class="reserved">if</span>(request.getPolicy() == draw2d.EditPolicy.DELETE)
  {
    <span class="reserved">if</span>(<span class="reserved">this</span>.isDeleteable()==true)
      <span class="reserved">return</span> new draw2d.CommandDelete(<span class="reserved">this</span>);
    <span class="reserved">return</span> null;
  }

  <span class="reserved">return</span> null;
};

</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Mon Nov 14 13:45:39 2011</div>
</body>
</html>
